<template>
  <div>
  <router-link to="seller-edit" class="el-button" style="float:right;margin:10px 0px">添加商家</router-link>
  <el-table
    :data="tableData"
	border
    style="width: 100%; margin: 10px 10px">
    <el-table-column
      prop="name"
      label="名称">
    </el-table-column>
	<el-table-column
      prop="category"
      label="分类">
    </el-table-column>
    <el-table-column
      prop="address"
      label="地址">
	</el-table-column>
	<el-table-column
      prop="sales"
      label="销量">
    </el-table-column>
	<el-table-column
      prop="dispatching_price"
      label="起送价">
    </el-table-column>
	<el-table-column
      prop="send_price"
      label="运费">
    </el-table-column>
	<el-table-column label="操作" width="255">
      <template slot-scope="scope">
		<el-button
          size="mini"
          @click="handleAdmin(scope.$index, scope.row)">管理员</el-button>
        <el-button
          size="mini"
          @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
    </el-table-column>
	
  </el-table>
  <el-pagination
	  background
	  layout="prev, pager, next"
	  :page-size="pagesize"
	  @current-change="currentPage"
	  :total="total">
	</el-pagination>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        tableData: [],
		pagesize : 10,
		total: 10,
		page: 1,
		
      }
    },
    methods: {
	  getSellerList(currentPage){
		this.$axios({
			method:"post",
			url:this.host+"/admin/index.php/Seller/getSellerList",
			data:{
				page: currentPage?parseInt(currentPage):this.page,
				pagesize: this.pagesize
			}
		}).then((res)=>{
			this.loading = false  
			console.log(res)
			this.tableData = res.data.list
			this.total = res.data.total
		})
	  },
	  currentPage(val){
		this.getSellerList(val)
	  },
	  handleEdit(index, row){
		this.$router.push({ path: 'seller-edit', query:{id:row.id}})
	  },
	  handleAdmin(index, row){
		this.$router.push({ path: 'seller-admin', query:{id:row.id}})
	  },
	  handleDelete(index, row){
		this.$axios({
			method:"post",
			url:this.host+"/admin/index.php/Seller/delSeller",
			data:{
				id: row.id,
			}
		}).then((res)=>{
			this.$message({
				  message: '删除成功',
				  type: 'success'
				});
			this.tableData.splice(index, 1);
		})
	  }
    },
    mounted: function mounted() {
        this.getSellerList();
    }
  }
</script>
